1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Net;
11 using System.IO;
12 using System.Text.RegularExpressions;
13 using System.Xml;
14 using HtmlAgilityPack;
15 using Fizzler.Systems.HtmlAgilityPack;
16
17
18
19 namespace SoftQuanLyNhaHang.Views
20 {
21 public partial class uctScanner : UserControl
22 {
23 public uctScanner()
24 {
25 InitializeComponent();
26 }
27
28 public static uctScanner uctSc = new uctScanner();
29
30 string tenSp = string.Empty;
31 string maSp = string.Empty;
32 string giaSp = string.Empty;
33 HtmlWeb hw = new HtmlWeb();
34 HtmlAgilityPack.HtmlDocument doc;//
35 int i = 0;
36
37 int layidUrl = 5088;
38
39 //private string urlWeb;
40 string tenDvT = string.Empty;
41 int index1 = -1;
42
43 DataTable dtUrl = new DataTable();
44 string _urlPath = string.Empty;
45 int timloisp = 0;
46
47 string[] loimang;
48
49
50 //lay url
51 private void layUrlWebSite_truonganmart_vn()
52 {
53 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
54 {
55 MessageBox.Show("Domain và Url không được để trống");
56 return;
57 }
58
59 ServicePointManager.Expect100Continue = true;
60 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
61
62 //lay url trong csdl
63 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
64 HtmlAttribute att;
65 int timloi = 0;
66 string urlInsertWebsite = "";
67 //tap hop lai cac url
68 string allUrl = "";
69
70 int viTriUrlTrongCsdl = 0;
71 string urlSql = "";
72
73 if (dtUrl.Rows.Count > 0)
74 {
75
76 foreach (DataRow item in dtUrl.Rows)
77 {
78 allUrl += item["UrlPath"].ToString() + ";";
79 }
80
81 //tim tung url trong trang theo url cha
82 foreach (DataRow item in dtUrl.Rows)
83 {
84 urlSql = item["UrlPath"].ToString();
85
86 timloi = 0;
87
88
89 if (urlSql.Contains("plus.google.com") == true)
90 {
91 timloi += 1;
92 }
93
94 if (urlSql.Contains("twitter.com") == true)
95 {
96 timloi += 1;
97 }
98
99 if (urlSql.Contains("www.facebook.com") == true)
100 {
101 timloi += 1;
102 }
103
104 if (urlSql.Contains("javascript") == true)
105 {
106 timloi += 1;
107 }
108
109 if (urlSql.Contains("software") == true)
110 {
111 timloi += 1;
112 }
113
114
115 if (urlSql.Contains("#") == true)
116 {
117 timloi += 1;
118 }
119
120 if (urlSql.Contains("https://codefly.vn") == false)
121 {
122 timloi += 1;
123 }
124
125 if (urlSql.Contains("about/") == true || urlSql.Contains("member/") == true)
126 {
127 timloi = +1;
128 }
129
130 if (timloi == 0)
131 {
132 doc = hw.Load(urlSql);
133
134 //var matchesList = new List<string>();
135 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
136 {
137 att = link.Attributes["href"];
138
139 //neu chua co url trong csdl thi insert
140 if (att.Value.Contains("https://codefly.vn") == false)
141 {
142 urlInsertWebsite = "https://codefly.vn" + att.Value;
143 }
144 else
145 {
146 urlInsertWebsite = att.Value;
147 }
148
149 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
150
151 if (viTriUrlTrongCsdl == -1)
152 {
153
154 timloi = 0;
155
156
157 if (att.Value.Contains("plus.google.com") == true)
158 {
159 timloi = +1;
160 }
161
162 if (att.Value.Contains("twitter.com") == true)
163 {
164 timloi = +1;
165 }
166
167 if (att.Value.Contains("www.facebook.com") == true)
168 {
169 timloi = +1;
170 }
171
172 if (att.Value.Contains("#") == true)
173 {
174 timloi = +1;
175 }
176
177 if (urlInsertWebsite.Contains("https://codefly.vn") == false)
178 {
179 timloi = +1;
180 }
181
182 if (att.Value.Contains("about/") == true || att.Value.Contains("member/") == true)
183 {
184 timloi = +1;
185 }
186
187 if (timloi == 0)
188 {
189
190 if (att.Value.Contains("https://codefly.vn") == false)
191 {
192 urlInsertWebsite = "https://codefly.vn" + att.Value;
193 }
194 else
195 {
196 urlInsertWebsite = att.Value;
197 }
198
199 allUrl += urlInsertWebsite + ";";
200
201 i = Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
202
203 if (i > 0)
204 {
205
206 }
207 }
208 }
209 }
210 }
211
212 //break;
213 }
214 }
215 else
216 {
217 Controllers.UrlWebCtrl.InsertUrlWeb(0, txtUrlPath.Text.Trim(), txtDomainLike.Text.Trim(), "SuDung");
218 }
219
220 //da xong tat cả
221 txtUrlCurrent.Text = timloi.ToString();
222 }
223
224 private void layUrlWebSite_www_goodmax_vn()
225 {
226 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
227 {
228 MessageBox.Show("Domain và Url không được để trống");
229 return;
230 }
231
232 ServicePointManager.Expect100Continue = true;
233 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
234
235 //lay url trong csdl
236 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
237 HtmlAttribute att;
238 int timloi = 0;
239 string urlInsertWebsite = "";
240 //tap hop lai cac url
241 string allUrl = "";
242
243 int viTriUrlTrongCsdl = 0;
244 string urlSql = "";
245
246 if (dtUrl.Rows.Count > 0)
247 {
248
249 //dua tat ca url tu csdl vao trong
250 foreach (DataRow item in dtUrl.Rows)
251 {
252 allUrl += item["UrlPath"].ToString() + ";";
253 }
254
255 //lay cac url chua load = 0
256 DataTable urlLoad0 = new DataTable();
257 urlLoad0 = Controllers.UrlWebCtrl.FillAllUrl_LoadLan0(txtDomainLike.Text.Trim()).Tables[0];
258
259 if (urlLoad0.Rows.Count > 0)
260 {
261 string[] txtgachngan;
262 int somasp = 0;
263
264 //tim tung url trong trang theo url cha
265 foreach (DataRow item in urlLoad0.Rows)
266 {
267 urlSql = item["UrlPath"].ToString();
268 timloi = 0;
269
270 //khong load san pham la chi tiet
271 txtgachngan = urlSql.Split('-');
272 somasp = 0;
273 if (txtgachngan.Length > 0)
274 {
275
276 foreach (string word in txtgachngan)
277 {
278 if (word.Contains(".html"))
279 {
280 somasp = word.Length;
281 if (somasp == 18 || somasp == 17)
282 {
283 timloi = 10;
284 //san pham lay dc ma
285 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 10);
286 }
287
288 break;
289 }
290 }
291 }
292
293 if (timloi != 10)
294 {
295 txtgachngan = urlSql.Split('/');
296 //somasp = 0;
297 if (txtgachngan.Length == 5)
298 {
299 //lay url khactu url nay
300 timloi = 0;
301 //da load lai lan 2
302 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 6);
303
304 }
305 else
306 {
307 timloi = 5;
308 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 5);
309 }
310
311 }
312
313
314
315
316 //tim url de load tiep
317 if (timloi == 0)
318 {
319 if (urlSql.Contains("plus.google.com") == true || urlSql.Contains("twitter.com") == true || urlSql.Contains("www.facebook.com") == true || urlSql.Contains("javascript") == true)
320 {
321 timloi += 1;
322 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
323 }
324
325 if (urlSql.Contains("software") == true)
326 {
327 timloi += 1;
328 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
329 }
330
331 if (urlSql.Contains("www.goodmax.vn/") == false)
332 {
333 timloi += 1;
334 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
335 }
336
337 //
338 if (urlSql.Contains("https://suangay.vn/category/banh-bong-lan-solite-47.html") == true)
339 {
340 timloi += 1;
341 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
342 }
343
344 if (urlSql.Contains("https://suangay.vn/category/banh-coc-yan-yan-49.html") == true)
345 {
346 timloi += 1;
347 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
348 }
349
350 if (urlSql.Contains("https://suangay.vn/category/nokia-co-899.html") == true)
351 {
352 timloi += 1;
353 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
354 }
355 }
356
357
358 if (timloi == 0)
359 {
360 doc = hw.Load(urlSql);
361
362 if (doc.DocumentNode.SelectNodes("//a[@href]") != null)
363 {
364 //update url duoc load = 1
365 //Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 1);
366
367 //var matchesList = new List<string>();
368 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
369 {
370 att = link.Attributes["href"];
371
372 //neu chua co url trong csdl thi insert
373 if (att.Value.Contains("https://suangay.vn") == false)
374 {
375 urlInsertWebsite = "https://suangay.vn" + att.Value;
376 }
377 else
378 {
379 urlInsertWebsite = att.Value;
380 }
381
382 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
383
384 if (viTriUrlTrongCsdl == -1)
385 {
386
387 timloi = 0;
388
389 //them vao url da loa
390 allUrl += urlInsertWebsite + ";";
391
392 if (att.Value.Contains("plus.google.com") == true || att.Value.Contains("twitter.com") == true || att.Value.Contains("www.facebook.com") == true || att.Value.Contains("javascript") == true)
393 {
394 timloi = +1;
395 }
396
397 if (att.Value.Contains("#") == true)
398 {
399 timloi = +1;
400 }
401
402 if (att.Value.Contains("www.goodmax.vn/") == false)
403 {
404 timloi += 1;
405 }
406
407 if (att.Value.Contains("https://suangay.vn/category/banh-bong-lan-solite-47.html") == true)
408 {
409 timloi += 1;
410 }
411
412 if (att.Value.Contains("https://suangay.vn/category/banh-coc-yan-yan-49.html") == true)
413 {
414 timloi += 1;
415 }
416
417 if (timloi == 0)
418 {
419
420 if (att.Value.Contains("https://suangay.vn") == false)
421 {
422 urlInsertWebsite = "https://suangay.vn" + att.Value;
423 }
424 else
425 {
426 urlInsertWebsite = att.Value;
427 }
428
429 allUrl += urlInsertWebsite + ";";
430
431
432 txtgachngan = urlInsertWebsite.Split('/');
433 //somasp = 0;
434 if (txtgachngan.Length == 5)
435 {
436 //lay url khactu url nay
437 //timloi = 0;
438 i = Controllers.UrlWebCtrl.Insert2_UrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung", DateTime.Now, 0);
439
440 }
441 else
442 {
443 //khong load san pham la chi tiet
444 txtgachngan = urlInsertWebsite.Split('-');
445 somasp = 0;
446 if (txtgachngan.Length > 0)
447 {
448
449 foreach (string word in txtgachngan)
450 {
451 if (word.Contains(".html"))
452 {
453 somasp = word.Length;
454 if (somasp == 18 || somasp == 17)
455 {
456 //san pham lay dc ma
457 i = Controllers.UrlWebCtrl.Insert2_UrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung", DateTime.Now, 10);
458
459 }
460 else
461 {
462 i = Controllers.UrlWebCtrl.Insert2_UrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung", DateTime.Now, 5);
463 }
464
465 break;
466 }
467 }
468 }
469
470 }
471
472
473
474 }
475 }
476 }
477 }
478 else
479 {
480 //url khong load
481 Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
482 }
483
484 //break;
485 }
486 //else
487 //{
488 //loi != 0
489 //Controllers.UrlWebCtrl.Update2_UrlWeb(urlSql, 2);
490
491 //}
492 }
493
494 //end if load lan dau
495 }//end if ulrload < 0
496
497
498 }
499 else
500 {
501 Controllers.UrlWebCtrl.Insert2_UrlWeb(0, txtUrlPath.Text.Trim(), txtDomainLike.Text.Trim(), "SuDung", DateTime.Now, 0);
502 }
503
504 //da xong tat cả
505 txtUrlCurrent.Text = timloi.ToString();
506 }
507
508 private void layUrlWebSite_truyxuat_com_vn()
509 {
510
511 }
512
513
514 //lay url
515 private void layUrlWebSite_depxinh_net()
516 {
517 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
518 {
519 MessageBox.Show("Domain và Url không được để trống");
520 return;
521 }
522
523 ServicePointManager.Expect100Continue = true;
524 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
525
526 //lay url trong csdl
527 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
528 HtmlAttribute att;
529 int timloi = 0;
530 string urlInsertWebsite = "";
531 //tap hop lai cac url
532 string allUrl = "";
533
534 int viTriUrlTrongCsdl = 0;
535 string urlSql = "";
536
537 if (dtUrl.Rows.Count > 0)
538 {
539
540 foreach (DataRow item in dtUrl.Rows)
541 {
542 allUrl += item["UrlPath"].ToString() + ";";
543 }
544
545 //tim tung url trong trang theo url cha
546 foreach (DataRow item in dtUrl.Rows)
547 {
548 urlSql = item["UrlPath"].ToString();
549
550 timloi = 0;
551
552 if (urlSql.Contains("plus.google.com") == true)
553 {
554 timloi = 1;
555 }
556
557 if (urlSql.Contains("twitter.com") == true)
558 {
559 timloi = 1;
560 }
561
562 if (urlSql.Contains("www.facebook.com") == true)
563 {
564 timloi = 1;
565 }
566
567 if (urlSql.Contains(".net/") == false)
568 {
569 timloi = 1;
570 }
571
572 if (timloi == 0)
573 {
574 doc = hw.Load(urlSql);
575
576 //var matchesList = new List<string>();
577 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
578 {
579 att = link.Attributes["href"];
580
581 //neu chua co url trong csdl thi insert
582 if (att.Value.Contains("https://www.depxinh.net") == false)
583 {
584 urlInsertWebsite = "https://www.depxinh.net" + att.Value;
585 }
586 else
587 {
588 urlInsertWebsite = att.Value;
589 }
590
591 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
592
593 if (viTriUrlTrongCsdl == -1)
594 {
595
596 timloi = 0;
597
598 if (att.Value.Contains("plus.google.com") == true)
599 {
600 timloi = 1;
601 }
602
603 if (urlSql.Contains("twitter.com") == true)
604 {
605 timloi = 1;
606 }
607
608 if (att.Value.Contains("www.facebook.com") == true)
609 {
610 timloi = 1;
611 }
612
613 if (att.Value.Contains(".net/") == false)
614 {
615 timloi = 1;
616 }
617
618 if (timloi == 0)
619 {
620
621 if (att.Value.Contains("https://www.depxinh.net") == false)
622 {
623 urlInsertWebsite = "https://www.depxinh.net" + att.Value;
624 }
625 else
626 {
627 urlInsertWebsite = att.Value;
628 }
629
630 allUrl += urlInsertWebsite + ";";
631
632 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
633 }
634 }
635 }
636 }
637 }
638 }
639 else
640 {
641 Controllers.UrlWebCtrl.InsertUrlWeb(0, txtUrlPath.Text.Trim(), txtDomainLike.Text.Trim(), "SuDung");
642 }
643
644 //da xong tat cả
645 txtUrlCurrent.Text = timloi.ToString();
646 }
647
648
649 //lay san pham sua
650 private void layUrlWebSite_suatot_vn()
651 {
652 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
653 {
654 MessageBox.Show("Domain và Url không được để trống");
655 return;
656 }
657
658 ServicePointManager.Expect100Continue = true;
659 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
660
661 //lay url trong csdl
662 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
663 HtmlAttribute att;
664 int timloi = 0;
665 string urlInsertWebsite = "";
666 //tap hop lai cac url
667 string allUrl = "";
668
669 int viTriUrlTrongCsdl = 0;
670 string urlSql = "";
671
672 if (dtUrl.Rows.Count > 0)
673 {
674
675 foreach (DataRow item in dtUrl.Rows)
676 {
677 allUrl += item["UrlPath"].ToString() + ";";
678 }
679
680 //tim tung url trong trang theo url cha
681 foreach (DataRow item in dtUrl.Rows)
682 {
683 urlSql = item["UrlPath"].ToString();
684 timloi = 0;
685
686 //urlSql
687 if (urlSql.Contains("plus.google.com") == true)
688 {
689 timloi = 1;
690 }
691
692 if (urlSql.Contains("twitter.com") == true)
693 {
694 timloi = 1;
695 }
696
697 if (urlSql.Contains("www.facebook.com") == true)
698 {
699 timloi = 1;
700 }
701
702 if (urlSql.Contains("https://remonline.vn/personal.html") == true)
703 {
704 timloi = 1;
705 }
706
707 //loi khong truy cap
708 if (urlSql.Contains("#") == true)
709 {
710 timloi = 1;
711 }
712
713 if (urlSql.Contains("javascript") == true)
714 {
715 timloi = 1;
716 }
717
718 if (urlSql.Contains("help.") == true)
719 {
720 timloi = 1;
721 }
722
723 if (urlSql.Contains("featured") == true)
724 {
725 timloi = 1;
726 }
727
728 if (urlSql.Contains("search") == true)
729 {
730 timloi = 1;
731 }
732
733 if (urlSql.Contains("vnregister") == true)
734 {
735 timloi = 1;
736 }
737
738
739 if (timloi == 0)
740 {
741
742 doc = hw.Load(urlSql);
743
744 //var matchesList = new List<string>();
745 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
746 {
747 att = link.Attributes["href"];
748
749 //neu chua co url trong csdl thi insert
750 if (att.Value.Contains("https://remonline.vn") == false)
751 {
752 urlInsertWebsite = "https://remonline.vn" + att.Value;
753 }
754 else
755 {
756 urlInsertWebsite = att.Value;
757 }
758
759 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
760
761 if (viTriUrlTrongCsdl == -1)
762 {
763
764 timloi = 0;
765
766 if (urlSql.Contains("#") == true)
767 {
768 timloi = 1;
769 }
770
771 if (att.Value.Contains("plus.google.com") == true)
772 {
773 timloi = 1;
774 }
775
776 if (urlSql.Contains("twitter.com") == true)
777 {
778 timloi = 1;
779 }
780
781 if (att.Value.Contains("www.facebook.com") == true)
782 {
783 timloi = 1;
784 }
785
786 if (urlSql.Contains("https://remonline.vn/personal.html") == true)
787 {
788 timloi = 1;
789 }
790
791 if (urlSql.Contains("#") == true)
792 {
793 timloi = 1;
794 }
795
796 if (urlSql.Contains("javascript") == true)
797 {
798 timloi = 1;
799 }
800
801 if (urlSql.Contains("help.") == true)
802 {
803 timloi = 1;
804 }
805
806 if (urlSql.Contains("featured") == true)
807 {
808 timloi = 1;
809 }
810
811 if (urlSql.Contains("search") == true)
812 {
813 timloi = 1;
814 }
815
816 if (urlSql.Contains("vnregister") == true)
817 {
818 timloi = 1;
819 }
820
821 if (timloi == 0)
822 {
823
824 if (att.Value.Contains("https://remonline.vn") == false)
825 {
826 urlInsertWebsite = "https://remonline.vn" + att.Value;
827 }
828 else
829 {
830 urlInsertWebsite = att.Value;
831 }
832
833 allUrl += urlInsertWebsite + ";";
834
835 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
836 }
837 }
838 }
839 }
840 }
841 }
842 else
843 {
844 //khong co url trong csdl
845 doc = hw.Load(txtUrlPath.Text.Trim());
846
847 //var matchesList = new List<string>();
848 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
849 {
850 att = link.Attributes["href"];
851
852 //neu chua co url trong csdl thi insert
853 timloi = 0;
854
855 if (att.Value.Contains("plus.google.com") == true)
856 {
857 timloi = 1;
858 }
859
860 if (att.Value.Contains("www.facebook.com") == true)
861 {
862 timloi = 1;
863 }
864
865 if (timloi == 0)
866 {
867
868 if (att.Value.Contains("https://remonline.vn") == false)
869 {
870 urlInsertWebsite = "https://remonline.vn" + att.Value;
871 }
872 else
873 {
874 urlInsertWebsite = att.Value;
875 }
876
877 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
878
879 if (viTriUrlTrongCsdl == -1)
880 {
881 allUrl += urlInsertWebsite + ";";
882
883 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
884 }
885
886 }
887
888
889
890 }
891 //
892 }
893
894 //da xong tat cả
895 txtUrlCurrent.Text = timloi.ToString();
896 }
897
898 //lay layUrlWebSite_tamart_vn
899 private void layUrlWebSite_tamart_vn()
900 {
901 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
902 {
903 MessageBox.Show("Domain và Url không được để trống");
904 return;
905 }
906
907 ServicePointManager.Expect100Continue = true;
908 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
909
910 //lay url trong csdl
911 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
912 HtmlAttribute att;
913 int timloi = 0;
914 string urlInsertWebsite = "";
915 //tap hop lai cac url
916 string allUrl = "";
917
918 int viTriUrlTrongCsdl = 0;
919 string urlSql = "";
920
921 if (dtUrl.Rows.Count > 0)
922 {
923 foreach (DataRow item in dtUrl.Rows)
924 {
925 allUrl += item["UrlPath"].ToString() + ";";
926 }
927
928 //tim tung url trong trang theo url cha
929 foreach (DataRow item in dtUrl.Rows)
930 {
931 timloi = 0;
932
933 urlSql = item["UrlPath"].ToString();
934
935 //urlSql
936 if (urlSql.Contains("plus.google.com") == true)
937 {
938 timloi = 1;
939 }
940
941 if (urlSql.Contains("www.facebook.com") == true)
942 {
943 timloi = 1;
944 }
945
946 if (urlSql.Contains("176?page=") == true || urlSql.Contains("187?page=") == true || urlSql.Contains("208?page=") == true || urlSql.Contains("54?page=") == true)
947 {
948
949 timloi = 1;
950 }
951
952 if (urlSql.Contains(".vn/") == false)
953 {
954 timloi = 1;
955 }
956
957 if (timloi == 0)
958 {
959 doc = hw.Load(urlSql);
960
961 //var matchesList = new List<string>();
962 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
963 {
964 att = link.Attributes["href"];
965
966 //neu chua co url trong csdl thi insert
967 if (att.Value.Contains("http://tamart.vn") == false)
968 {
969 urlInsertWebsite = "http://tamart.vn" + att.Value;
970 }
971 else
972 {
973 urlInsertWebsite = att.Value;
974 }
975
976 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
977
978 if (viTriUrlTrongCsdl == -1)
979 {
980
981 timloi = 0;
982
983 if (att.Value.Contains(".vn/") == false)
984 {
985 timloi = 1;
986 }
987
988 if (att.Value.Contains("plus.google.com") == true)
989 {
990 timloi = 1;
991 }
992
993 if (att.Value.Contains("www.facebook.com") == true)
994 {
995 timloi = 1;
996 }
997
998 if (urlSql.Contains("176?page=") == true || urlSql.Contains("187?page=") == true || urlSql.Contains("208?page=") == true || urlSql.Contains("54?page=") == true)
999 {
1000
1001 timloi = 1;
1002 }
1003
1004 if (timloi == 0)
1005 {
1006
1007 if (att.Value.Contains("http://tamart.vn") == false)
1008 {
1009 urlInsertWebsite = "http://tamart.vn" + att.Value;
1010 }
1011 else
1012 {
1013 urlInsertWebsite = att.Value;
1014 }
1015
1016 allUrl += urlInsertWebsite + ";";
1017
1018 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
1019 }
1020 }
1021 }
1022 }
1023 }
1024 }
1025 else
1026 {
1027 //khong co url trong csdl
1028 doc = hw.Load(txtUrlPath.Text.Trim());
1029
1030 //var matchesList = new List<string>();
1031 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1032 {
1033 att = link.Attributes["href"];
1034
1035
1036
1037 //neu chua co url trong csdl thi insert
1038 timloi = 0;
1039
1040 if (att.Value.Contains("plus.google.com") == true)
1041 {
1042 timloi = 1;
1043 }
1044
1045 if (att.Value.Contains("www.facebook.com") == true)
1046 {
1047 timloi = 1;
1048 }
1049
1050 if (timloi == 0)
1051 {
1052
1053 if (att.Value.Contains("http://tamart.vn") == false)
1054 {
1055 urlInsertWebsite = "http://tamart.vn" + att.Value;
1056 }
1057 else
1058 {
1059 urlInsertWebsite = att.Value;
1060 }
1061
1062 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
1063
1064 if (viTriUrlTrongCsdl == -1)
1065 {
1066 allUrl += urlInsertWebsite + ";";
1067
1068 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
1069 }
1070
1071 }
1072
1073
1074
1075 }
1076 //
1077 }
1078
1079 //da xong tat cả
1080 txtUrlCurrent.Text = timloi.ToString();
1081 }
1082
1083 //tim url taphoasua.com
1084 private void layUrlTapHoaSua_Com()
1085 {
1086 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
1087 {
1088 MessageBox.Show("Domain và Url không được để trống");
1089 return;
1090 }
1091
1092 ServicePointManager.Expect100Continue = true;
1093 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
1094
1095 //lay url trong csdl
1096 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
1097 HtmlAttribute att;
1098 int timloi = 0;
1099 string urlInsertWebsite = "";
1100
1101 if (dtUrl.Rows.Count > 0)
1102 {
1103 //tap hop lai cac url
1104 string allUrl = "";
1105 foreach (DataRow item in dtUrl.Rows)
1106 {
1107 allUrl += item["UrlPath"].ToString() + ";";
1108 }
1109
1110 int viTriUrlTrongCsdl = 0;
1111 string urlSql = "";
1112
1113
1114 //tim tung url trong trang theo url cha
1115 foreach (DataRow item in dtUrl.Rows)
1116 {
1117 urlSql = item["UrlPath"].ToString();
1118
1119 //urlSql
1120 if (urlSql.Contains("plus.google.com") == true)
1121 {
1122 timloi = 1;
1123 }
1124
1125 if (urlSql.Contains("www.facebook.com") == true)
1126 {
1127 timloi = 1;
1128 }
1129
1130 if (timloi == 0)
1131 {
1132
1133 doc = hw.Load(urlSql);
1134
1135 //var matchesList = new List<string>();
1136 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1137 {
1138 att = link.Attributes["href"];
1139
1140 //neu chua co url trong csdl thi insert
1141
1142 if (att.Value.Contains("..") == true)
1143 {
1144 urlInsertWebsite = "https://remonline.vn" + att.Value.Replace("..", "");
1145 }
1146 else
1147 {
1148 if (att.Value.Contains("https://remonline.vn") == false)
1149 {
1150 urlInsertWebsite = "https://remonline.vn" + att.Value;
1151 }
1152 else
1153 {
1154 urlInsertWebsite = att.Value;
1155 }
1156 }
1157
1158 viTriUrlTrongCsdl = allUrl.LastIndexOf(urlInsertWebsite);// "I want to learn \"C#\""
1159
1160 if (viTriUrlTrongCsdl == -1 && att.Value.Contains("vi-vn") == true)
1161 {
1162 timloi = 0;
1163
1164 //if (att.Value.Contains(".com") == true)
1165 // {
1166 // timloi = 1;
1167 // }
1168
1169 if (att.Value.Contains("plus.google.com") == true)
1170 {
1171 timloi = 1;
1172 }
1173
1174 if (att.Value.Contains("www.facebook.com") == true)
1175 {
1176 timloi = 1;
1177 }
1178
1179 if (timloi == 0)
1180 {
1181 if (att.Value.Contains("..") == true)
1182 {
1183 urlInsertWebsite = "https://remonline.vn" + att.Value.Replace("..", "");
1184 }
1185 else
1186 {
1187 if (att.Value.Contains("https://remonline.vn") == false)
1188 {
1189 urlInsertWebsite = "https://remonline.vn" + att.Value;
1190 }
1191 else
1192 {
1193 urlInsertWebsite = att.Value;
1194 }
1195 }
1196 allUrl += urlInsertWebsite + ";";
1197
1198 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
1199 }
1200 }
1201 }
1202 }
1203 }
1204 }
1205 else
1206 {
1207 //khong co url trong csdl
1208 doc = hw.Load(txtUrlPath.Text.Trim());
1209
1210 //var matchesList = new List<string>();
1211 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1212 {
1213 att = link.Attributes["href"];
1214
1215 //neu chua co url trong csdl thi insert
1216 if (att.Value.Contains("vi-vn"))
1217 {
1218 timloi = 0;
1219
1220 if (att.Value.Contains("plus.google.com") == true)
1221 {
1222 timloi = 1;
1223 }
1224
1225 if (att.Value.Contains("www.facebook.com") == true)
1226 {
1227 timloi = 1;
1228 }
1229
1230 if (timloi == 0)
1231 {
1232
1233 if (att.Value.Contains("..") == true)
1234 {
1235 urlInsertWebsite = "https://remonline.vn" + att.Value.Replace("..","");
1236 }
1237 else
1238 {
1239 if (att.Value.Contains("https://remonline.vn") == false)
1240 {
1241 urlInsertWebsite = "https://remonline.vn" + att.Value;
1242 }
1243 else
1244 {
1245 urlInsertWebsite = att.Value;
1246 }
1247 }
1248
1249 Controllers.UrlWebCtrl.InsertUrlWeb(0, urlInsertWebsite, txtDomainLike.Text.Trim(), "SuDung");
1250 }
1251
1252 }
1253
1254
1255 }
1256 //
1257 }
1258
1259 //da xong tat cả
1260 txtUrlCurrent.Text = timloi.ToString();
1261 }
1262
1263 private void layUrlWebSite12gmart_Com()
1264 {
1265 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
1266 {
1267 MessageBox.Show("Domain và Url không được để trống");
1268 return;
1269 }
1270
1271 ///
1272 //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
1273 //--https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
1274 ServicePointManager.Expect100Continue = true;
1275 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
1276
1277
1278 //lay url trong csdl
1279 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
1280 HtmlAttribute att;
1281 int timloi = 0;
1282
1283
1284 if (dtUrl.Rows.Count > 0)
1285 {
1286 //tap hop lai cac url
1287 string allUrl = "";
1288 foreach (DataRow item in dtUrl.Rows)
1289 {
1290 allUrl += item["UrlPath"].ToString().Replace("amp;", "") + ";";
1291 }
1292
1293 int viTriUrlTrongCsdl = 0;
1294 string urlSql = "";
1295
1296
1297 //tim tung url trong trang theo url cha
1298 foreach (DataRow item in dtUrl.Rows)
1299 {
1300 urlSql = item["UrlPath"].ToString().Replace("amp;", "");
1301
1302
1303 //urlSql
1304 if (urlSql.Contains(".com") == true && urlSql.Contains("taphoasua") == false)
1305 {
1306 timloi = 1;
1307 }
1308
1309 if (urlSql.Contains("plus.google.com") == true)
1310 {
1311 timloi = 1;
1312 }
1313
1314 if (urlSql.Contains("www.facebook.com") == true)
1315 {
1316 timloi = 1;
1317 }
1318
1319 if (timloi == 0)
1320 {
1321
1322 doc = hw.Load(urlSql);
1323
1324 //var matchesList = new List<string>();
1325 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1326 {
1327 att = link.Attributes["href"];
1328 //neu chua co url trong csdl thi insert
1329 viTriUrlTrongCsdl = allUrl.LastIndexOf(att.Value.Replace("amp;", ""));// "I want to learn \"C#\""
1330
1331 if (viTriUrlTrongCsdl == -1 && att.Value.Replace("amp;", "").Contains(txtDomainLike.Text.Trim()) == true)
1332 {
1333 //Controllers.UrlWebCtrl.InsertUrlWeb(0, att.Value, txtDomainLike.Text.Trim(), "SuDung");
1334 timloi = 0;
1335
1336 if (att.Value.Contains("plus.google.com") == true)
1337 {
1338 timloi = 1;
1339 }
1340
1341 if (att.Value.Contains("www.facebook.com") == true)
1342 {
1343 timloi = 1;
1344 }
1345
1346 if (timloi == 0)
1347 {
1348 Controllers.UrlWebCtrl.InsertUrlWeb(0, att.Value, txtDomainLike.Text.Trim(), "SuDung");
1349 }
1350 }
1351 }
1352 }
1353
1354
1355
1356 }
1357
1358 }
1359 else
1360 {
1361 //khong co url trong csdl
1362 doc = hw.Load(txtUrlPath.Text.Trim());
1363
1364 //var matchesList = new List<string>();
1365 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1366 {
1367 att = link.Attributes["href"];
1368 //neu chua co url trong csdl thi insert
1369 if (att.Value.Contains(txtDomainLike.Text.Trim()))
1370 {
1371 timloi = 0;
1372
1373 if (att.Value.Contains(".com") == true && att.Value.Contains("taphoasua") == false)
1374 {
1375 timloi = 1;
1376 }
1377
1378 if (att.Value.Contains("plus.google.com") == true)
1379 {
1380 timloi = 1;
1381 }
1382
1383 if (att.Value.Contains("www.facebook.com") == true)
1384 {
1385 timloi = 1;
1386 }
1387
1388 if (timloi == 0)
1389 {
1390 Controllers.UrlWebCtrl.InsertUrlWeb(0, att.Value, txtDomainLike.Text.Trim(), "SuDung");
1391 }
1392
1393 }
1394
1395 }
1396 //
1397 }
1398
1399 //da xong tat cả
1400 txtUrlCurrent.Text = timloi.ToString();
1401 }
1402
1403 private void btnGetUrl_Click(object sender, EventArgs e)
1404 {
1405 if (txtDomainLike.Text.Contains("www.taphoasua.com") == true)
1406 {
1407 this.layUrlTapHoaSua_Com();
1408 }
1409
1410 if (txtDomainLike.Text.Contains("www.12gmart.com") == true)
1411 {
1412 this.layUrlWebSite12gmart_Com();
1413 }
1414
1415 if (txtDomainLike.Text.Contains("tamart.vn") == true)
1416 {
1417 this.layUrlWebSite_tamart_vn();
1418 }
1419
1420 if (txtDomainLike.Text.Contains("suatot.vn") == true)
1421 {
1422 this.layUrlWebSite_suatot_vn();
1423 }
1424
1425 if (txtDomainLike.Text.Contains("www.depxinh.net") == true)
1426 {
1427 this.layUrlWebSite_depxinh_net();
1428 }
1429
1430 //truyxuat.com.vn loi
1431 if (txtDomainLike.Text.Contains("truyxuat.com.vn") == true)
1432 {
1433 this.layUrlWebSite_truyxuat_com_vn();
1434 }
1435
1436 if (txtDomainLike.Text.Contains("www.goodmax.vn") == true)
1437 {
1438 this.layUrlWebSite_www_goodmax_vn();
1439 }
1440
1441 if (txtDomainLike.Text.Contains("truonganmart.vn") == true)
1442 {
1443 this.layUrlWebSite_truonganmart_vn();
1444 }
1445
1446 }
1447
1448 //khong dc xóa
1449 private void LayUrl_12gmart_com()
1450 {
1451 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
1452 {
1453 MessageBox.Show("Domain và Url không được để trống");
1454 return;
1455 }
1456
1457 //lay url trong csdl
1458 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
1459
1460 if (dtUrl.Rows.Count > 0)
1461 {
1462 //tap hop lai cac url
1463 string allUrl = "";
1464 foreach (DataRow item in dtUrl.Rows)
1465 {
1466 allUrl += item["UrlPath"].ToString().Replace("amp;", "") + ";";
1467 }
1468
1469 int viTriUrlTrongCsdl = 0;
1470 //tim tung url trong trang theo url cha
1471 foreach (DataRow item in dtUrl.Rows)
1472 {
1473
1474
1475 doc = hw.Load(item["UrlPath"].ToString().Replace("amp;", ""));
1476
1477 //var matchesList = new List<string>();
1478 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1479 {
1480 HtmlAttribute att = link.Attributes["href"];
1481 //neu chua co url trong csdl thi insert
1482 viTriUrlTrongCsdl = allUrl.LastIndexOf(att.Value.Replace("amp;", ""));// "I want to learn \"C#\""
1483
1484 if (viTriUrlTrongCsdl == -1 && att.Value.Replace("amp;", "").Contains(txtDomainLike.Text.Trim()) == true)
1485 {
1486 Controllers.UrlWebCtrl.InsertUrlWeb(0, att.Value, txtDomainLike.Text.Trim(), "SuDung");
1487 }
1488
1489
1490
1491 }
1492 }
1493
1494 }
1495 else
1496 {
1497 //khong co url trong csdl
1498 doc = hw.Load(txtUrlPath.Text.Trim());
1499
1500 //var matchesList = new List<string>();
1501 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
1502 {
1503 HtmlAttribute att = link.Attributes["href"];
1504 //neu chua co url trong csdl thi insert
1505 if (att.Value.Contains(txtDomainLike.Text.Trim()))
1506 {
1507 Controllers.UrlWebCtrl.InsertUrlWeb(0, att.Value, txtDomainLike.Text.Trim(), "SuDung");
1508 }
1509
1510 }
1511 //
1512 }
1513 }
1514
1515
1516 //--https://www.dotnetperls.com/recursion
1517 static int Recursive(int value, ref int count)
1518 {
1519 count++;
1520 if (value >= 10)
1521 {
1522 // throw new Exception("End");
1523 return value;
1524 }
1525 return Recursive(value + 1, ref count);
1526 }
1527
1528 private void Recurse(int remaining)
1529 {
1530 // This method could be optimized with tail recursion.
1531 if (remaining <= 0)
1532 {
1533 return;
1534 }
1535
1536 Recurse(remaining - 1);
1537 }
1538
1539
1540 private bool KiemTraTonTai(string url)
1541 {
1542 bool coTonTai = false;
1543 //string value = this.getAllHtmlDomWeb(url);
1544 string htmlString = url;
1545
1546 return coTonTai;
1547 }
1548
1549 private HttpStatusCode GetHeaders(string url)
1550 {
1551 HttpStatusCode result = default(HttpStatusCode);
1552
1553 var request = HttpWebRequest.Create(url);
1554 request.Method = "HEAD";
1555 using (var response = request.GetResponse() as HttpWebResponse)
1556 {
1557 if (response != null)
1558 {
1559 result = response.StatusCode;
1560 response.Close();
1561 }
1562 }
1563
1564 return result;
1565 }
1566
1567 //https://stackoverflow.com/questions/16642196/get-html-code-from-website-in-c-sharp
1568 //lay html trong website
1569 private string getAllHtmlDomWeb(string tHtml)
1570 {
1571 string txtHtml = "";
1572
1573 string urlAddress = tHtml;
1574
1575 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
1576 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
1577 //HttpStatusCode status = response.StatusCode;
1578
1579 if (response.StatusCode == HttpStatusCode.OK)
1580 {
1581 Stream receiveStream = response.GetResponseStream();
1582 StreamReader readStream = null;
1583
1584 if (response.CharacterSet == null)
1585 {
1586 readStream = new StreamReader(receiveStream);
1587 }
1588 else
1589 {
1590 readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
1591 }
1592
1593 txtHtml = readStream.ReadToEnd();
1594
1595 response.Close();
1596 readStream.Close();
1597
1598
1599 }
1600
1601 return txtHtml;
1602 }
1603
1604
1605 int demlap = 0;
1606 string txtHtml = string.Empty;
1607
1608 //khong dc copy, viet ham dac biet
1609 private void insert_truonganmart_vn(string urlP)
1610 {
1611 timloisp = 0;
1612
1613
1614 if (urlP.Contains("plus.google.com") == true)
1615 {
1616 timloisp += 1;
1617 }
1618
1619 if (urlP.Contains("twitter.com") == true)
1620 {
1621 timloisp += 1;
1622 }
1623
1624 if (urlP.Contains("www.facebook.com") == true)
1625 {
1626 timloisp += 1;
1627 }
1628
1629 if (urlP.Contains("javascript") == true)
1630 {
1631 timloisp += 1;
1632 }
1633
1634 if (urlP.Contains("software") == true)
1635 {
1636 timloisp += 1;
1637 }
1638
1639
1640 if (urlP.Contains("#") == true)
1641 {
1642 timloisp += 1;
1643 }
1644
1645 if (urlP.Contains("https://codefly.vn") == false)
1646 {
1647 timloisp += 1;
1648 }
1649
1650 if (urlP.Contains("about/") == true || urlP.Contains("member/") == true)
1651 {
1652 timloisp = +1;
1653 }
1654
1655 //kiem tra ton tai url la chi tiet san pham
1656 if (timloisp == 0 && urlP.Contains("https://codefly.vn") == true)
1657 {
1658 doc = hw.Load(urlP);
1659
1660 //doc the tieu de H2
1661 if (doc.DocumentNode.SelectNodes("//h1") != null)
1662 {
1663 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h1"))
1664 {
1665 tenSp = h2.InnerText.Trim();
1666 //txtTenSanPham.Text = tenSp;
1667 break;
1668 }
1669
1670 //
1671 //ma san pham
1672 if (doc.DocumentNode.SelectNodes("//div[@id='productInfor']") != null)
1673 {
1674 //ma san pham
1675
1676 foreach (HtmlNode txt in doc.DocumentNode.SelectNodes("//div[@id='productInfor']"))
1677 {
1678 //txtHtml = txt.InnerHtml;
1679 //maSp = maSp.Replace("Mã sản phẩm:", "").Trim();
1680 demlap = 0;
1681 maSp = string.Empty;
1682 tenDvT = string.Empty;
1683 //giaSp = string.Empty;
1684
1685 foreach (HtmlNode x in txt.SelectNodes("p"))
1686 {
1687 demlap += 1;
1688
1689 txtHtml = x.InnerText.Trim();
1690
1691 if (demlap == 3)
1692 {
1693 //ma san pham
1694 maSp = x.InnerText.Trim();
1695 maSp = maSp.Replace("Mã vạch: ","").Trim();
1696 }
1697
1698 if (demlap == 4)
1699 {
1700 //don vi tinh
1701 tenDvT = x.InnerText.Trim();
1702 tenDvT = tenDvT.Replace("Đơn vị tính: ","").Trim();
1703
1704 break;
1705 }
1706
1707 //if (demlap == 6)
1708 ///{
1709 // //gia sp
1710 // giaSp = x.InnerText.Trim();
1711 // giaSp = giaSp.Replace("Giá bán: ", "").Replace("đ", "").Replace(",","").Replace(".","").Trim();
1712 //}
1713
1714 }
1715 break;
1716 }
1717
1718 giaSp = "";
1719 //gia ban
1720 if (doc.DocumentNode.SelectNodes("//p[@id='lbGiaBan1']") != null)
1721 {
1722 //gia ban <div class="">
1723 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//p[@id='lbGiaBan1']"))
1724 {
1725 foreach (HtmlNode g in gb.SelectNodes("//span[@class='curent-price']"))
1726 {
1727 giaSp = g.InnerText.Trim();
1728 giaSp = giaSp.Replace("Giá bán: ", "").Replace("đ", "").Replace(",", "").Replace(".", "").Trim();
1729
1730 break;
1731 }
1732
1733 }
1734 }
1735
1736 if (!string.IsNullOrEmpty(maSp))
1737 {
1738 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 0);
1739 }
1740 }
1741 }
1742
1743
1744
1745
1746
1747
1748
1749 //}
1750 }
1751 }
1752
1753 private void insert_www_goodmax_vn(string urlP)
1754 {
1755 timloisp = 0;
1756
1757 //urlSql
1758 if (urlP.Contains("plus.google.com") == true)
1759 {
1760 timloisp = 1;
1761 }
1762
1763 if (urlP.Contains("twitter.com") == true)
1764 {
1765 timloisp = 1;
1766 }
1767
1768 if (urlP.Contains("www.facebook.com") == true)
1769 {
1770 timloisp = 1;
1771 }
1772
1773 if (urlP.Contains("javascript") == true)
1774 {
1775 timloisp = 1;
1776 }
1777
1778 //loi khong truy cap
1779 if (urlP.Contains("#") == true)
1780 {
1781 timloisp = 1;
1782 }
1783
1784 if (urlP.Contains("category") == true)
1785 {
1786 timloisp = 1;
1787 }
1788
1789
1790
1791 //kiem tra ton tai url la chi tiet san pham
1792 if (timloisp == 0 && urlP.Contains("https://suangay.vn/") == true)
1793 {
1794 doc = hw.Load(urlP);
1795
1796 //doc the tieu de H2
1797 if (doc.DocumentNode.SelectNodes("//h2[@class='product_name']") != null)
1798 {
1799 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h2[@class='product_name']"))
1800 {
1801 tenSp = h2.InnerText.Trim();
1802 txtTenSanPham.Text = tenSp;
1803 break;
1804 }
1805 }
1806 else
1807 {
1808 tenSp = "";
1809 }
1810
1811 //ma san pham
1812 if (doc.DocumentNode.SelectNodes("//p[@class='product_code']") != null)
1813 {
1814 //ma san pham
1815
1816 foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//p[@class='product_code']"))
1817 {
1818 maSp = msp.InnerText.Trim();
1819 maSp = maSp.Replace("Mã sản phẩm:","").Trim();
1820 break;
1821 }
1822 }
1823 else
1824 {
1825 maSp = "";
1826 }
1827
1828
1829 //gia ban
1830 if (doc.DocumentNode.SelectNodes("//p[@class='price']") != null)
1831 {
1832 //gia ban <div class="">
1833 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//p[@class='price']"))
1834 {
1835 giaSp = gb.InnerText.Trim();
1836 giaSp = giaSp.Replace(".", "").Replace("Giá bán:", "").Replace("đ", "").Replace(" ₫","").Replace(",","").Trim();
1837
1838 // string[] txtgsp = giaSp.Split(' ');
1839 //foreach (string word in txtgsp)
1840 //{
1841 // giaSp = word.Trim();
1842 // break;
1843 //}
1844
1845 break;
1846 }
1847 }
1848 else
1849 {
1850 giaSp = "";
1851 }
1852
1853
1854
1855 if (!string.IsNullOrEmpty(maSp))
1856 {
1857 tenDvT = string.Empty;
1858
1859 index1 = tenSp.LastIndexOf('/');
1860 if (index1 != -1)
1861 {
1862 tenDvT = tenSp.Substring(index1).Replace("/", "").Trim();
1863 }
1864
1865 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 0);
1866 }
1867 //}
1868 }
1869 }
1870
1871 private void insert_depxinh_net(string urlP)
1872 {
1873 timloisp = 0;
1874
1875 //urlSql
1876 if (urlP.Contains("plus.google.com") == true)
1877 {
1878 timloisp = 1;
1879 }
1880
1881 if (urlP.Contains("twitter.com") == true)
1882 {
1883 timloisp = 1;
1884 }
1885
1886 if (urlP.Contains("www.facebook.com") == true)
1887 {
1888 timloisp = 1;
1889 }
1890
1891 if (urlP.Contains("javascript") == true)
1892 {
1893 timloisp = 1;
1894 }
1895
1896 //loi khong truy cap
1897 if (urlP.Contains("#") == true)
1898 {
1899 timloisp = 1;
1900 }
1901
1902 //kiem tra ton tai url la chi tiet san pham
1903 if (timloisp == 0 && urlP.Contains(".net/s/") == false)
1904 {
1905 doc = hw.Load(urlP);
1906
1907 //doc the tieu de H2
1908 if (doc.DocumentNode.SelectNodes("//h1") != null)
1909 {
1910 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h1"))
1911 {
1912 tenSp = h2.InnerText.Trim();
1913 txtTenSanPham.Text = tenSp;
1914 break;
1915 }
1916 }
1917 else
1918 {
1919 tenSp = "";
1920 }
1921
1922 //ma san pham
1923 if (doc.DocumentNode.SelectNodes("//td[@class='lbl-blue']") != null)
1924 {
1925 //ma san pham
1926
1927 //var value = doc.DocumentNode.SelectNodes("//td[@class='lbl-blue']").First().InnerText.Trim();
1928
1929 //string x = value.ToString();
1930 string ms = "";
1931 foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//td[@class='lbl-blue']"))
1932 {
1933 ms = msp.InnerText.Trim();
1934 // maSp = maSp.Trim().Replace(" ","");
1935 string[] txtgsp = ms.Split(' ');
1936 foreach (string word in txtgsp)
1937 {
1938 maSp = word.Trim();
1939 break;
1940 }
1941
1942 break;
1943 }
1944 }
1945 else
1946 {
1947 maSp = "";
1948 }
1949
1950
1951 //gia ban
1952 if (doc.DocumentNode.SelectNodes("//div[@class='pprice']") != null)
1953 {
1954 //gia ban <div class="">
1955 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//div[@class='pprice']"))
1956 {
1957 giaSp = gb.InnerText.Trim();
1958 giaSp = giaSp.Replace(".", "").Replace("Giá: ", "").Replace("đ", "").Trim();
1959
1960 // string[] txtgsp = giaSp.Split(' ');
1961 //foreach (string word in txtgsp)
1962 //{
1963 // giaSp = word.Trim();
1964 // break;
1965 //}
1966
1967 break;
1968 }
1969 }
1970 else
1971 {
1972 giaSp = "";
1973 }
1974
1975
1976 /*
1977 //don vi tinh
1978 if (doc.DocumentNode.SelectNodes("//div[@class='c_style']") != null)
1979 {
1980 //gia ban <div class="">
1981 foreach (HtmlNode dvt in doc.DocumentNode.SelectNodes("//div[@class='c_style']"))
1982 {
1983 tenDvT = dvt.InnerText.Trim();
1984 tenDvT = tenDvT.Replace(",", "").Replace("Chủng loại:", "").Trim();
1985 break;
1986 }
1987 }
1988 else
1989 {
1990 tenDvT = "";
1991 }
1992 */
1993
1994 if (!string.IsNullOrEmpty(maSp))
1995 {
1996 //index1 = tenSp.LastIndexOf('/');
1997 //if (index1 != -1)
1998 //{
1999 // tenDvT = tenSp.Substring(index1).Replace("/", "").Trim();
2000 //}
2001
2002 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 0);
2003 }
2004 //}
2005 }
2006 }
2007
2008 //sua tot lay tt sp
2009 private void insert_suatot_vn(string urlP)
2010 {
2011
2012 timloisp = 0;
2013
2014 //urlSql
2015 if (urlP.Contains("plus.google.com") == true)
2016 {
2017 timloisp = 1;
2018 }
2019
2020 if (urlP.Contains("twitter.com") == true)
2021 {
2022 timloisp = 1;
2023 }
2024
2025 if (urlP.Contains("www.facebook.com") == true)
2026 {
2027 timloisp = 1;
2028 }
2029
2030 if (urlP.Contains("https://remonline.vn/personal.html") == true)
2031 {
2032 timloisp = 1;
2033 }
2034
2035 //loi khong truy cap
2036 if (urlP.Contains("#") == true)
2037 {
2038 timloisp = 1;
2039 }
2040
2041 if (urlP.Contains("javascript") == true)
2042 {
2043 timloisp = 1;
2044 }
2045
2046 if (urlP.Contains("help.") == true)
2047 {
2048 timloisp = 1;
2049 }
2050
2051 if (urlP.Contains("featured") == true)
2052 {
2053 timloisp = 1;
2054 }
2055
2056 if (urlP.Contains("search") == true)
2057 {
2058 timloisp = 1;
2059 }
2060
2061 if (urlP.Contains("vnregister") == true)
2062 {
2063 timloisp = 1;
2064 }
2065
2066
2067 //kiem tra ton tai url la chi tiet san pham
2068 if (timloisp == 0 && urlP.Contains("detail"))
2069 {
2070
2071 doc = hw.Load(urlP);
2072
2073 //if (this.KiemTraTonTai(urlP))
2074 //{
2075 //doc the tieu de H2
2076 if (doc.DocumentNode.SelectNodes("//h1[@class='c_title_name fn']") != null)
2077 {
2078 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h1[@class='c_title_name fn']"))
2079 {
2080 //tmlAttribute att = link.Attributes["H2"];
2081 tenSp = h2.InnerText.Trim();
2082 txtTenSanPham.Text = tenSp;
2083 break;
2084 }
2085 }
2086 else
2087 {
2088 tenSp = "";
2089 }
2090
2091 //ma san pham
2092 //
2093 string[] txturl = urlP.Split('-');
2094 foreach (string word in txturl)
2095 {
2096 if (word.Contains(".html"))
2097 {
2098 maSp = word.Replace(".html", "").Trim();
2099
2100 }
2101 }
2102
2103 //gia ban
2104 if (doc.DocumentNode.SelectNodes("//strong[@class='prize price']") != null)
2105 {
2106 //gia ban <div class="">
2107 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//strong[@class='prize price']"))
2108 {
2109 giaSp = gb.InnerText.Trim();
2110 giaSp = giaSp.Replace(",", "").Trim();
2111
2112 string[] txtgsp = giaSp.Split(' ');
2113 foreach (string word in txtgsp)
2114 {
2115 giaSp = word.Trim();
2116 break;
2117 }
2118
2119 break;
2120 }
2121 }
2122 else
2123 {
2124 giaSp = "";
2125 }
2126
2127
2128 //don vi tinh
2129 if (doc.DocumentNode.SelectNodes("//div[@class='c_style']") != null)
2130 {
2131 //gia ban <div class="">
2132 foreach (HtmlNode dvt in doc.DocumentNode.SelectNodes("//div[@class='c_style']"))
2133 {
2134 tenDvT = dvt.InnerText.Trim();
2135 tenDvT = tenDvT.Replace(",", "").Replace("Chủng loại:","").Trim();
2136 break;
2137 }
2138 }
2139 else
2140 {
2141 tenDvT = "";
2142 }
2143
2144
2145 if (!string.IsNullOrEmpty(maSp))
2146 {
2147 //index1 = tenSp.LastIndexOf('/');
2148 //if (index1 != -1)
2149 //{
2150 // tenDvT = tenSp.Substring(index1).Replace("/", "").Trim();
2151 //}
2152
2153 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 0);
2154 }
2155 //}
2156 }
2157 }
2158
2159 //lay thong tin sp
2160 private void insert_tamart_vn(string urlP)
2161 {
2162
2163 timloisp = 0;
2164
2165 if (urlP.Contains("about") == true)
2166 {
2167
2168 }
2169
2170 if (urlP.Contains("javascript") == true)
2171 {
2172
2173 }
2174
2175 //kiem tra ton tai url la chi tiet san pham
2176 if (urlP.Contains(".vn/") == true && timloisp == 0)
2177 {
2178 doc = hw.Load(urlP);
2179
2180 //if (this.KiemTraTonTai(urlP))
2181 //{
2182 //doc the tieu de H2
2183 if (doc.DocumentNode.SelectNodes("//h1[@id='prodName']") != null)
2184 {
2185 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h1[@id='prodName']"))
2186 {
2187 //tmlAttribute att = link.Attributes["H2"];
2188 tenSp = h2.InnerText.Trim();
2189 txtTenSanPham.Text = tenSp;
2190 break;
2191 }
2192 }
2193 else
2194 {
2195 tenSp = "";
2196 }
2197
2198 if (doc.DocumentNode.SelectNodes("//div[@id='productInfor']") != null)
2199 {
2200
2201 //ma san pham
2202 foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//div[@id='productInfor']"))
2203 {
2204 demlap = 0;
2205 foreach (HtmlNode node2 in msp.SelectNodes(".//p"))
2206 {
2207 demlap += 1;
2208 if (demlap == 2)
2209 {
2210 maSp = node2.InnerText.Trim();
2211 maSp = maSp.Replace("Mã vạch: ", "");
2212 //break;
2213 }
2214
2215 if (demlap == 3)
2216 {
2217 tenDvT = node2.InnerText.Trim();
2218 tenDvT = tenDvT.Replace("Đơn vị tính: ", "");
2219 //break;
2220 }
2221
2222 }
2223
2224 }
2225 }
2226 else
2227 {
2228 maSp = "";
2229 }
2230
2231 if (doc.DocumentNode.SelectNodes("//p[@id='lbGiaBan1']") != null)
2232 {
2233 //gia ban <div class="">
2234 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//p[@id='lbGiaBan1']"))
2235 {
2236 giaSp = gb.InnerText.Trim();
2237 giaSp = giaSp.Replace("Giá bán: ","").Replace("VNĐ", "").Replace(",", "").Trim();
2238 //txtGiaBan.Text = giaSp;
2239 break;
2240 }
2241 }
2242 else
2243 {
2244 giaSp = "";
2245 }
2246
2247
2248 //don vi tinh
2249 if (!string.IsNullOrEmpty(maSp))
2250 {
2251 //index1 = tenSp.LastIndexOf('/');
2252 //if (index1 != -1)
2253 //{
2254 // tenDvT = tenSp.Substring(index1).Replace("/", "").Trim();
2255 //}
2256
2257 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 0);
2258 }
2259 //}
2260 }
2261 }
2262
2263 //lay thon tin san pham
2264 private void insert_12gmart_com(string urlP)
2265 {
2266 //kiem tra ton tai url la chi tiet san pham
2267 if (urlP.Contains("product/product"))
2268 {
2269 //-http://www.12gmart.com/index.php?route=product/product&path=659&product_id=7871
2270 doc = hw.Load(urlP);
2271
2272 //if (this.KiemTraTonTai(urlP))
2273 //{
2274 //doc the tieu de H2
2275 if (doc.DocumentNode.SelectNodes("//h2") != null)
2276 {
2277 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h2"))
2278 {
2279 //tmlAttribute att = link.Attributes["H2"];
2280 tenSp = h2.InnerText.Trim();
2281 txtTenSanPham.Text = tenSp;
2282 break;
2283 }
2284 }
2285 else
2286 {
2287 tenSp = "";
2288 }
2289
2290 if (doc.DocumentNode.SelectNodes("//div[@class='description']") != null)
2291 {
2292 //ma san pham
2293 foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//div[@class='description']"))
2294 {
2295 //tmlAttribute att = link.Attributes["H2"];
2296 maSp = msp.InnerText.Trim();
2297 maSp = maSp.Replace("Mã sản phẩm:", "").Replace("Tình trạng:", "").Replace("Còn hàng", "");
2298 txtMaSanPham.Text = maSp.Trim();
2299 break;
2300 }
2301 }
2302 else
2303 {
2304 maSp = "";
2305 }
2306
2307 if (doc.DocumentNode.SelectNodes("//div[@class='price']") != null)
2308 {
2309 //gia ban <div class="">
2310 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//div[@class='price']"))
2311 {
2312 //tmlAttribute att = link.Attributes["H2"];
2313 giaSp = gb.InnerText.Trim();
2314 giaSp = giaSp.Replace("đ", "").Replace(".", "");
2315 txtGiaBan.Text = giaSp;
2316 break;
2317 }
2318 }
2319 else
2320 {
2321 giaSp = "";
2322 }
2323 //don vi tinh
2324 if (!string.IsNullOrEmpty(maSp))
2325 {
2326 index1 = tenSp.LastIndexOf('/');
2327 if (index1 != -1)
2328 {
2329 tenDvT = tenSp.Substring(index1).Replace("/", "").Trim();
2330 }
2331
2332 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 1);
2333 }
2334 //}
2335 }
2336 }
2337
2338 //lay thong tin san pham insert_taphoasua_com
2339 private void insert_taphoasua_com(string urlP)
2340 {
2341 //kiem tra ton tai url la chi tiet san pham
2342 if (urlP.Contains("https://remonline.vn/vi-vn/Pr-") == true)
2343 {
2344 doc = hw.Load(urlP);
2345
2346 //doc the tieu de H2
2347 if (doc.DocumentNode.SelectNodes("//h1[@class='product-title text-vnns']") != null)
2348 {
2349 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h1[@class='product-title text-vnns']"))
2350 {
2351 tenSp = h2.InnerText.Trim();
2352 txtTenSanPham.Text = tenSp;
2353 break;
2354 }
2355 }
2356 else
2357 {
2358 tenSp = "";
2359 }
2360
2361 if (doc.DocumentNode.SelectNodes("//h3[@class='product-code text-vnns']") != null)
2362 {
2363 //ma san pham
2364 foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//h3[@class='product-code text-vnns']"))
2365 {
2366 maSp = msp.InnerText.Trim();
2367 maSp = maSp.Replace("Mã sản phẩm", "").Replace(":", "");
2368 txtMaSanPham.Text = maSp.Trim();
2369 break;
2370 }
2371 }
2372 else
2373 {
2374 maSp = "";
2375 }
2376
2377
2378 giaSp = "0";
2379
2380 //don vi tinh
2381 if (!string.IsNullOrEmpty(maSp))
2382 {
2383 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urlP, DateTime.Now, 0);
2384 }
2385
2386 }
2387 }
2388
2389 //tim thong tin san pham
2390 private void insert_matrala_vn(string urPath)
2391 {
2392 timloisp = 0;
2393
2394 if (urPath.Contains("khuyen-mai-he"))
2395 {
2396 timloisp = 1;
2397 }
2398
2399 if (urPath.Contains("thang-6"))
2400 {
2401 timloisp = 1;
2402 }
2403
2404 if (urPath.Contains("author"))
2405 {
2406 timloisp = 1;
2407 }
2408
2409 if (urPath.Contains(".jpg"))
2410 {
2411 timloisp = 1;
2412 }
2413
2414 loimang = urPath.Split('/');
2415
2416 if (loimang.Length <= 6)
2417 {
2418 timloisp = 1;
2419 }
2420
2421 if (timloisp == 0)
2422 {
2423 //--https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
2424 ServicePointManager.Expect100Continue = true;
2425 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
2426
2427 doc = hw.Load(urPath);
2428
2429 //doc the tieu de H2
2430 foreach (HtmlNode h2 in doc.DocumentNode.SelectNodes("//h1"))
2431 {
2432 //tmlAttribute att = link.Attributes["H2"];
2433 tenSp = h2.InnerText.Trim();
2434 txtTenSanPham.Text = tenSp;
2435 }
2436
2437 //ma san pham
2438 //foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//div[@class='description']"))
2439 if (doc.DocumentNode.SelectNodes("//span[@class='sku']") != null)
2440 {
2441 foreach (HtmlNode msp in doc.DocumentNode.SelectNodes("//span[@class='sku']"))
2442 {
2443 //tmlAttribute att = link.Attributes["H2"];
2444 maSp = msp.InnerText.Trim();
2445 maSp = maSp.Replace("Mã sản phẩm:", "").Replace("Tình trạng:", "").Replace("Còn hàng", "");
2446 txtMaSanPham.Text = maSp.Trim();
2447 }
2448 }
2449 else
2450 {
2451 maSp = "Khong_ton_tai";
2452 }
2453
2454
2455 //gia ban <div class="">
2456
2457 foreach (HtmlNode gb in doc.DocumentNode.SelectNodes("//span[@class='woocommerce-Price-amount amount']"))
2458 {
2459 //tmlAttribute att = link.Attributes["H2"];
2460 giaSp = gb.InnerText.Trim();
2461 giaSp = giaSp.Replace("đ", "").Replace(".", "");
2462 giaSp = giaSp.Replace(",", "").Replace("₫", "");
2463 txtGiaBan.Text = giaSp;
2464 }
2465
2466
2467 //ten don vi tinh
2468 if (doc.DocumentNode.SelectNodes("//div[@class='panel entry-content active']") != null)
2469 {
2470
2471 foreach (HtmlNode dvt in doc.DocumentNode.SelectNodes("//div[@class='panel entry-content active']"))
2472 {
2473 tenDvT = dvt.InnerText.Trim();
2474 }
2475
2476 string[] tendonvitinh = tenDvT.Split(':');
2477
2478 if (tendonvitinh.Length == 2)
2479 {
2480 tenDvT = tendonvitinh[1];
2481 }
2482
2483 txtDonViTinh.Text = tenDvT;
2484
2485 }
2486 else
2487 {
2488 tenDvT = "xxxxx";
2489 }
2490
2491 //
2492
2493 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, maSp, tenSp, 0, giaSp, 0, tenDvT, urPath, DateTime.Now, 1);
2494
2495 }
2496
2497 txtUrlCurrent.Text = urPath;
2498
2499 }
2500
2501
2502 private void btnStart_Click(object sender, EventArgs e)
2503 {
2504
2505
2506 if (string.IsNullOrEmpty(txtDomainLike.Text.Trim()) || string.IsNullOrEmpty(txtUrlPath.Text.Trim()))
2507 {
2508 MessageBox.Show("Domain và Url không được để trống");
2509 return;
2510 }
2511
2512 //dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl(txtDomainLike.Text.Trim()).Tables[0];
2513 dtUrl = Controllers.UrlWebCtrl.FillAllDsUrl_getTenGiaMaSp(txtDomainLike.Text.Trim()).Tables[0];
2514
2515 if (dtUrl.Rows.Count > 0)
2516 {
2517
2518 foreach (DataRow item in dtUrl.Rows)
2519 {
2520
2521 _urlPath = item["UrlPath"].ToString().Replace("amp;", "");
2522
2523 if (_urlPath.Contains("www.taphoasua.com"))
2524 {
2525 this.insert_taphoasua_com("https://remonline.vn/vi-vn/Pr-sua-bot-ensure-gold-vani-lon-900g-2209-1.html");
2526 }
2527
2528 if (_urlPath.Contains("www.12gmart.com"))
2529 {
2530 this.insert_12gmart_com(_urlPath);
2531 }
2532
2533 if (_urlPath.Contains("matrala.vn"))
2534 {
2535 this.insert_matrala_vn(_urlPath);
2536 }
2537
2538 if (_urlPath.Contains("tamart.vn"))
2539 {
2540 this.insert_tamart_vn(_urlPath);
2541 }
2542
2543 if (_urlPath.Contains("suatot.vn"))
2544 {
2545 this.insert_suatot_vn(_urlPath);
2546 }
2547
2548 if (_urlPath.Contains("www.depxinh.net"))
2549 {
2550 this.insert_depxinh_net(_urlPath);
2551 }
2552
2553 if (_urlPath.Contains("www.goodmax.vn"))
2554 {
2555 this.insert_www_goodmax_vn(_urlPath);
2556 }
2557
2558 if (_urlPath.Contains("truonganmart.vn"))
2559 {
2560 this.insert_truonganmart_vn(_urlPath);
2561 }
2562
2563 }
2564 }
2565 else
2566 {
2567 this.insert_12gmart_com("http://www.12gmart.com/index.php?route=product/product&path=333_674&product_id=6152");
2568 }
2569
2570
2571 }
2572
2573
2574 private static string getSubstring(string source, string start, string end)
2575 {
2576 int startIndex = source.IndexOf(start) + start.Length;
2577 int length = source.IndexOf(end, startIndex) - startIndex;
2578 return source.Substring(startIndex, length);
2579 }
2580
2581 private static string getDomainName(string url)
2582 {
2583 int length = url.IndexOf("/", 8);
2584 string domainName = url.Substring(0, length);
2585 return domainName;
2586 }
2587
2588 private void btnTimUrl_Click(object sender, EventArgs e)
2589 {
2590 btnTimUrl.Visible = false;
2591 //--http://www.12gmart.com/index.php?route=product/product&product_id=5748
2592 string urlNew = "http://www.12gmart.com/index.php?route=product/product&product_id=";
2593 string urlMoi = "";
2594 bool x = false;
2595 //--5000
2596 //for (int uid = 5040; uid < 5060; uid++)
2597 //{
2598 urlMoi = urlNew + layidUrl.ToString();
2599 x = UrlFound(urlMoi);
2600
2601 if (x == true)
2602 {
2603 txtUrlCurrent.Text = urlMoi;
2604 i = Controllers.UrlWebCtrl.InsertUrlWeb(0, urlMoi, txtDomainLike.Text.Trim(), "SuDung_GetById");
2605 //continue;
2606 }
2607 layidUrl += 1;
2608
2609 txtDonViTinh.Text = layidUrl.ToString();
2610 // }
2611
2612 var t = new System.Windows.Forms.Timer();
2613 t.Interval = 3000; // it will Tick in 3 seconds
2614 t.Tick += (s, ex) =>
2615 {
2616 btnTimUrl.Visible = true;
2617 this.btnTimUrl_Click(sender,e);
2618 t.Stop();
2619 };
2620 t.Start();
2621
2622
2623 }
2624
2625 private bool UrlFound(string url)
2626 {
2627 ServicePointManager.Expect100Continue = true;
2628 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
2629 try
2630 {
2631
2632 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
2633 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
2634 return true;
2635 }
2636 catch (WebException we)
2637 {
2638 HttpWebResponse errorResponse = we.Response as HttpWebResponse;
2639 if (errorResponse != null)
2640 if (errorResponse.StatusCode == HttpStatusCode.NotFound)
2641 {
2642 return false;
2643 }
2644 else
2645 throw; //we only look for 404 Error
2646 }
2647 return false;
2648 }
2649
2650 private void LayUrl_12gmart_com_GetSatatus()
2651 {
2652
2653 }
2654 }
2655 }